﻿using System;
using NDBGen.Descriptors.Columns.Tokens;
using NDBGen.Plugins.DataAccess;

namespace NDBGen.Plugins.Descriptors.Columns.Tokens
{
    [ColumnTokenCodeSnippetGenerator(typeof(NullableTokenDescriptor))]
    public sealed class DotNetNullableTokenCodeGenerator : DotNetColumnTokenCodeGeneratorBase<NullableTokenDescriptor>
    {
        protected override Object[] GenerateColumnAttributeProperties()
        {
            if (String.IsNullOrEmpty(this.Descriptor.TokenValue))
            {
                return new Object[]
                {
                    ColumnMetadataHelper.ColumnAttribute.CanBeNull.False
                };
            }
            else
            {
                return new Object[]
                {
                    ColumnMetadataHelper.ColumnAttribute.CanBeNull.True
                };
            }
        }

        protected override Object[] GenerateCustomAttributes()
        {            
            if (String.IsNullOrEmpty(this.Descriptor.TokenValue))
            {
                return new Object[]
                {
                    ColumnMetadataHelper.CustomAttributes.Required
                };
            }
            else
            {
                return ColumnMetadataHelper.NoCustomAttributes;
            }
        }
    }
}